package com.xxd.spring.boot.demo.wubolin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.wubolin.Result;
import com.xxd.spring.boot.demo.wubolin.entity.Student;
import com.xxd.spring.boot.demo.wubolin.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.List;


@RestController
@RequestMapping("/student")
public class StudentController {
    //查信息
    @Autowired
    private StudentMapper studentMapper;

    @RequestMapping(value="/liststudent")
    public Result listStudent(Page page,@RequestParam Map<String,Object> params)  {
        IPage rePage = studentMapper.listPage(page,params);
        return new Result().setData(rePage);
    }

    //添加信息
    @RequestMapping(value="/addstudent")
    public Result addStudent(@RequestBody Student student)  {
        studentMapper.insert(student);
        return new Result().success();
    }

    //删除信息
    @RequestMapping(value="/delstudent/{id}")
    public Result delStudent(@PathVariable("id") Integer id)  {
        studentMapper.mydeleteData(id);
        return new Result().success();
    }

    //修改
    @RequestMapping(value="/updatestudent")
    public Result updateStudent(@RequestBody Student student)  {
        studentMapper.myupdateData(student);
        return new Result().success();
    }

    //成绩查询
    @RequestMapping("/stufraction/{num}")
    public Result stuFraction(@PathVariable("num") String num){
        Student stufraction = studentMapper.stuFraction(num);
        return new Result().success().setData(stufraction);
    }

    @RequestMapping("/all")
    public Result all(){
        List<Student> list = studentMapper.all();
        return new Result().success().setData(list);
    }
}
